%{
/* $Header: gram.y,v 2.2 01/10/02 10:27:01 przybyls Exp $ */
/*
   file: gram.y

     This yacc(1) input file defines the grammar recognized by the IQ
     message compiler.

   author: John DeGood, May 92
*/
#include "cm.h"
%}
%union {
	char *str;
       }
%token	ENDMARKER	0
%token	<str>	STRING
%token	<str>	WORD
%token  <str>   ET
%token  <str>   ST
%token  <str>   CT
%token  <str>   SETPT_CLASS
%token  <str>   MSG
%token  <str>   RPT
%token  <str>   GLP
%token  <str>   CLASS
%token  <str>   STATUS_MSG
%token  <str>   EOL
%token  <str>   CONV_CODE
%token  <str>   SETPT_NAME
%%
prog		: defns ENDMARKER
			{
			}
		;
defns		: /* nothing */
                | defns exception_type
                | defns setpt
                | defns repeat
                | defns class
                | defns conversion
		| defns entry
                | defns glp_info
                | defns msg_name
                | defns status_msg
                | defns conv_msg
                | defns setpt_type
                | defns setpt_name  
                | defns setpt_class  
		| defns junk
			{
			}
		;

exception_type  : ET WORD WORD WORD WORD
                {
                      CreateType( $2, $3, $4, $5 );
                      free( $2 );
                      free( $3 );
                      free( $4 );
                      free( $5 );
                };

setpt_type      : ST WORD 
                {
                      CreateSetptType( $2 );
                      free( $2 );
                };

repeat          : RPT WORD 
                {
                      CreateRepeat( $2 );
                      free( $2 );
                };
             
class           : CLASS WORD 
                {
                      CreateClass( $2 );
                      free( $2 );
                };

conversion      : CT WORD 
                {
                      CreateConv( $2 );
                      free( $2 );
                };

setpt_class     : SETPT_CLASS WORD 
                {
                      CreateSetptClass( $2 );
                      free( $2 );
                };

glp_info        :  GLP  WORD WORD
                {
                     if ( SetGlpInfo( Last_Entry_Name, $2, $3) != 0 )
                     {
                         strcpy ( Error, "P1 Can't Find " );
                         yyerror( strcat( Error, Last_Entry_Name) );
                     }
                     free( $2 );
                     free( $3 );
                };

setpt: WORD WORD EOL
{
                                switch ( "AddSetpt: %d\n", AddSetpt( $1, $2)  )
                                {
                                    case -1: strcpy ( Error, "Bad Exception : " );
                                             yyerror( strcat( Error, $1 ) );
                                             break;
                                    default: strcpy( Last_Entry_Name, $2 );
                                }
                                free( $1 );
                                free( $2 );
        
}

entry	: WORD WORD WORD WORD
			{

                                switch ( "AddEntry: %d\n", AddEntry( $1, $2, $3, $4 )  )
                                {
                                    case -1: strcpy ( Error, "Bad Exception : " );
                                             yyerror( strcat( Error, $1 ) );
                                             break;
                                    case -2: strcpy ( Error, "Bad Noise Parm: " );
                                             yyerror( strcat( Error, $3 ) );
                                             break;
                                    case -3: strcpy ( Error, "Bad Repeater:   " );
                                             yyerror( strcat( Error, $4 ) );
                                             break;
                                    default: strcpy( Last_Entry_Name, $2 );
                                }
                                free( $1 );
                                free( $2 );
                                free( $3 );
                                free( $4 );
			}
		;


msg_name        : MSG WORD
                {
                     if ( SetMsgName( Last_Entry_Name, $2 ) != 0 )
                     {
                         strcpy ( Error, "Msg Can't Find " );
                         yyerror( strcat( Error, Last_Entry_Name ) );
                     }
                     free( $2 );
                };


status_msg      : STATUS_MSG WORD
                {
                     if ( SetStatusMsgName( Last_Entry_Name, $2 ) != 0 )
                     {
                         strcpy ( Error, "Msg Can't Find " );
                         yyerror( strcat( Error, Last_Entry_Name ) );
                     }
                     free( $2 );
                };

conv_msg        : CONV_CODE WORD
                {
                     switch ( SetConvName( Last_Entry_Name, $2 ) )
                     {
                       case -1:
                         strcpy ( Error, "Conv Can't Find " );
                         yyerror( strcat( Error, Last_Entry_Name ) );
                         break;
                       case -2:
                         strcpy ( Error, "Conv: bad conv type: " );
                         yyerror( strcat( Error, $2 ) );
                         break;
                     }
                     free( $2 );
                };

setpt_name      : SETPT_NAME WORD
                {
                     switch ( SetSetptClass( Last_Entry_Name, $2 ) )
                     {
                       case -1:
                         strcpy ( Error, "Type Can't Find " );
                         yyerror( strcat( Error, Last_Entry_Name ) );
                         break;
                       case -2:
                         strcpy ( Error, "Type: bad Type type: " );
                         yyerror( strcat( Error, $2 ) );
                         break;
                     }
                     free( $2 );
                };

junk            : STRING
                   {
                       printf ( "%s\n", $1 );
                       free( $1 );
                   }
                ;
%%
#include "cm.c"
